//
//  UIViewController+Extension.swift
//  FrameProduct
//
//  Created by delegate on 2024/2/3.
//

import UIKit

extension UIViewController {
    class func initializeMethod() {
        #if DEBUG
        try! Swizzler.swizzle(selector: #selector(present(_:animated:completion:)),
                              newSelector: #selector(swizzler_present(_:animated:completion:)),
                              aClass: UIViewController.self)
        #endif
    }

    @objc private func swizzler_present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
        // 忽略切换appicon时的系统弹框
        if viewControllerToPresent .isKind(of: UIAlertController.self) {
            let alertController = viewControllerToPresent as? UIAlertController
            if alertController?.title == nil && alertController?.message == nil && alertController?.preferredStyle == .alert {
                return
            }
        }
        swizzler_present(viewControllerToPresent, animated: flag, completion: completion)
    }

}
